home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 41
/
Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso
/
Aminet
/
comm
/
tcp
/
rxsocket.lha
/
rxsocket
/
examples
/
ip2if.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
2000-11-28
|
3KB
|
109 lines
/* route example: shows the name of the interface used for an address */
l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
if AddLibrary("rexxsupport.library","rxsocket.library","rxlibnet.library")~=0 then exit
prg=ProgramName("NOEXT")
if ~IsLibOn("SOCKET") then do
say "No tcp/ip stack is running."
say "Remember: this macro works ONLY with Miami."
exit
end
if ~IsLibOn("MIAMI") then do
say "This macro works ONLY with Miami."
exit
end
if ~open("STDERR","CONSOLE:","W") then stderr="STDOUT"
if ~RMH_ReadArgs("ADDRESS/A") then do
call PrintFault()
exit
end
addr=resolve(parm.0.value)
if addr=-1 then call err "can't resolve <"parm.0.value">",1
s=socket("ROUTE","RAW")
if s<0 then call err "no socket"
len = 92+16
type = char(4)
pid = MiamiGetPid()
seq = long(1)
rtm = short(len) /* u_short rtm_msglen */
rtm = rtm || char(4) /* u_char rtm_version; */
rtm = rtm || type /* u_char rtm_type; */
rtm = rtm || short(0) /* u_short rtm_index */
rtm = rtm || short(0) /* u_short rtm_pad1; */
rtm = rtm || long(0) /* long rtm_flags; */
rtm = rtm || long(or(1,16)) /* long rtm_addrs */
rtm = rtm || pid /* void *rtm_pid */
rtm = rtm || seq /* long rtm_seq */
rtm = rtm || long(0) /* long rtm_errno */
rtm = rtm || long(0) /* long rtm_use */
rtm = rtm || long(0) /* u_long rtm_inits */
rtm = rtm || nul(56) /* struct rt_metrics rtm_rmx */
sin = char(16) /* u_char sin_len */
sin = sin || char(2) /* u_char sin_family */
sin = sin || short(0) /* u_short sin_port */
sin = sin || pad(addr2c(addr),4) /* struct in_addr sin_addr */
sin = sin || nul(8) /* char sin_zero[8] */
rtm = rtm || sin
if send(s,rtm,len)<0 then do
if Errno()~=3 then call err "send error"
say "<"addr"> is unreacheble"
exit
end
do until res<=0 | (t=type & se=seq & p=pid)
res = recv(s,"RTM",1024)
if res>0 then
parse var rtm d +2 d +1 t +1 index +2 d +2 d +4 d +4 p +4 se +4 rest
end
if res<0 then call err "recv error"
if=MiamiIFIndexToName(c2d(index))
if if="" then do
say "<"addr"> is unreacheble"
exit
end
if ~Datatype(right(if,1),"N") then if=if"0"
sd=socket("INET","DGRAM")
if s<0 then call err "socket error"
if IoctlSocket(sd,"SIOCGIFADDR",if,"IFADDR")<0 then call err "ioctl error"
say "<"addr"> -> '"if"' ["IFAddr"]"
exit
err: procedure expose prg stderr
parse arg msg,ntdoerr
if ntdoerr~=1 then msg = msg "("ErrorString()")"
call writeln(stderr,prg":" msg)
exit
pad: procedure
parse arg c,i
return right(copies("00"x,i)||c,i)
char: procedure
parse arg i
return d2c(i)
short: procedure
parse arg i
return right("0000"x||d2c(i),2)
long: procedure
parse arg i
return right("00000000"x||d2c(i),4)
nul: procedure
parse arg i
return copies("00"x,i)